Back to Editorials CodeCraft β
  • Github
  • Instagram
< >

Canteen Accountant

TIME LIMIT = 1 SEC.

  • People purchase food all throughout the day at the canteen. And it becomes difficult to keep track of all the purchases. To counter this, the owners decided to write every purchase and expenditure in a book. But even this becomes tedious because of thousands of purchases happening every day.
    Now the canteen owners are asking for your help to design a simple app to make note of purchases and expenditures and give closing balance at the end of the day. The app only has two commands - GET and GIVE.
    There are N purchases every day, and GET indicates when money comes in because of a sale and GIVE indicates money going out.Sometimes there may be spelling mistakes in commands. If you find spelling mistakes, ignore them.
    Assume that starting balance = 0.
Input Output
First line will contain N, number of transactions. Then the transactions follow.
Each transaction contains of a command - GET or GIVE followed by the amount after a single space.
Print the closing balance.
Constraints
  • 1 ≤ N ≤ 1000
  • 1 ≤ Transaction Amount ≤ 1000
Example Test Case
Input             Output
5
GET 100
GIVE 50
GIVE 25
GET 75
GIVE 50
50
Solution

#include <iostream> #include <string> using namespace std; int main() { long balance=0; int n,amount; cin>>n;//take n string command;//to store command while(n--) { cin>>command>>amount; //get command and amount if(command=="GET") //GET balance+=amount; else if(command=="GIVE") //GIVE balance-=amount; else //SPELLING MISTAKE continue; } cout<<balance; return 0; }
  • #1 Thieves
  • #2 The Queue of Doubts
  • #3 Summation of Primes
  • #4 Spacious Maximus
  • #5 Samosas
  • #6 Reasonably Sound
  • #7 Product of Digits
  • #8 Prime Usernames
  • #9 Path Shifter
  • #10 Keypad Count
  • #11 Even Vowels
  • #12 Encryption
  • #13 Decryption
  • #14 Canteen Accountant
  • #15 Attendance Register
  • #16 Amazing Year

Get in touch

  • executives@codingstudio.club
  • +91 9010342360
  • Vignana Bharthi Instute of Technology
    Aushapur, Ghatkesar, Hyderabad, Telengana - India

© coding.Studio();